package com.CloudDream.Command.Admin;

import com.CloudDream.Inventory.InventoryItem;
import com.CloudDream.MoonCake;
import com.handy.lib.command.IHandyCommandEvent;
import com.handy.lib.util.BaseUtil;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;

public class TakeCommand implements IHandyCommandEvent {
    @Override
    public String command() {
        return "take";
    }

    @Override
    public String permission() {
        return "mooncake.take";
    }

    @Override
    public void onCommand(CommandSender commandSender, Command command, String s, String[] args) {
        if(BaseUtil.isPlayer(commandSender).booleanValue()){
            commandSender.sendMessage(MoonCake.prefix + "§c该指令只能由控制台使用");
            return;
        }

        Player p = Bukkit.getPlayer(args[1]);
        (new BukkitRunnable(){
            @Override
            public void run() {
                for (int i = 0; i < 40; ++i) {
                    ItemStack pi = p.getInventory().getItem(i);
                    if (pi != null) {
                        switch (args[2]) {
                            case "lr":
                                if (pi.getItemMeta().getLore().equals(InventoryItem.getMoonCake(0).getItemMeta().getLore())) {
                                    pi.setAmount(pi.getAmount() - 1);
                                }
                                break;
                            case "wr":
                                if (pi.getItemMeta().getLore().equals(InventoryItem.getMoonCake(1).getItemMeta().getLore())) {
                                    pi.setAmount(pi.getAmount() - 1);
                                }
                                break;
                            case "dh":
                                if (pi.getItemMeta().getLore().equals(InventoryItem.getMoonCake(2).getItemMeta().getLore())) {
                                    pi.setAmount(pi.getAmount() - 1);
                                }
                                break;
                            case "bt":
                                if (pi.getItemMeta().getLore().equals(InventoryItem.getMoonCake(3).getItemMeta().getLore())) {
                                    pi.setAmount(pi.getAmount() - 1);
                                }
                                break;
                            case "mg":
                                if (pi.getItemMeta().getLore().equals(InventoryItem.getMoonCake(4).getItemMeta().getLore())) {
                                    pi.setAmount(pi.getAmount() - 1);
                                }
                                break;
                            case "gw":
                                if (pi.getItemMeta().getLore().equals(InventoryItem.getMoonCake(5).getItemMeta().getLore())) {
                                    pi.setAmount(pi.getAmount() - 1);
                                }
                                break;
                            case "rs":
                                if (pi.getItemMeta().getLore().equals(InventoryItem.getMoonCake(6).getItemMeta().getLore())) {
                                    pi.setAmount(pi.getAmount() - 1);
                                }
                                break;
                        }
                    }
                }
            }
        }).runTaskAsynchronously(MoonCake.getInstance());
    }
}
